const Service = require('egg').Service;
class WebService extends Service {

  async  add({ id, productName, artNo, price, content, cover, banner, info, stock, marketPrice, isdel = 0, sale }) {
    if (!id)


      return await this.app.mysql.insert('product', { productName, artNo, price, content, cover, banner, info, stock, marketPrice, sale });
    else
      return await this.app.mysql.update('product', { productName, artNo, price, content, cover, banner, info, sale, stock, marketPrice, id });
  }

  async  addimg({ id, url, isUse = 0, uid = 1 }) {
    if (!id)
      return await this.app.mysql.insert('wx_img', { url, isUse, uid });
    else
      return await this.app.mysql.update('wx_img', { url, isUse, id, uid });
  }
  async  getGoods({ id, page = 1, limit = 10 }) {
    var data = { // 搜索 post 表
      // where: { status: 'draft', author: ['author1', 'author2'] }, // WHERE 条件
      // columns: ['author', 'title'], // 要查询的表字段
      orders: ['id'], // 排序方式
      limit, // 返回数据量
      offset: (page - 1) * 10, // 数据偏移量
    }
    if (!id)
      return await this.app.mysql.select('product', data);
    else
      return await this.app.mysql.get('product', { id });

  }

  async  getTotal(tabber) {
    var data = { // 搜索 post 表
      where: { isdel: 0 }, // WHERE 条件
      columns: ['id'], // 要查询的表字段
    }
    var list = await this.app.mysql.select(tabber, data);
    return list.length
  }


}
module.exports = WebService;